#include "gamelevellayer.h"

Scene* GameLevelLayer::createScene(void)
{
    Scene* scene = Scene::create();
    GameLevelLayer* layer = GameLevelLayer::create();

    scene->addChild(layer);
    return scene;
}

#include <unistd.h>
#define RES "/home/wowk/Test/Cocos2D-x/Mario-build/bin/Resources/"
bool GameLevelLayer::init(void)
{
    if( !Layer::init() ){
        return false;
    }

    const Size & winSize = Director::getInstance()->getWinSize();
    float scale = winSize.height/224;

    player = Player::create();
    std::cout << getcwd(NULL,0);
    player->loadResources(RES"Mario.sprite",RES"Mario.png");
    player->setPosition(100,100);
    player->setAnchorPoint(Vec2(0.5,0));

    curLevelMap = TMXTiledMap::create(RES"MarioMap1-1.tmx");
    curLevelMap->setScale(scale,scale);
    curLevelMap->addChild(player,10);

    addChild(curLevelMap);

    scheduleUpdate();
    return true;
}

void GameLevelLayer::checkCollision(void)
{
    player->checkMoveRange(curLevelMap,objList);
}

void GameLevelLayer::updateObjects(float delta)
{
    player->update(delta);
}

void GameLevelLayer::update(float delta)
{
    checkCollision();
    updateObjects(delta);
    std::cout << player->getPositionX() << ":" << player->getPositionY() << std::endl;
}

